package com.example.springbootexam.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.springbootexam.bean.Paper;
import com.example.springbootexam.bean.PaperDetail;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author ly
 * @since 2024-08-14
 */
public interface PaperMapper extends BaseMapper<Paper> {

    @Select("select * from paper where id=#{id}")
    @Results(id="rm1",
             value={
                @Result(column = "id",property = "id", id = true),
                @Result(column = "id",property = "details", many = @Many(
                        select = "selectDetailByPid"
                ))
             })
    Paper findById(int id);

    @Select("select * from paper_detail where pid=#{pid}")
    @Results(id="rm2",
            value={
                    @Result(column = "id",property = "id", id = true),
                    @Result(column = "qid",property = "qid"),
                    @Result(column = "qid",property = "question", one = @One(
                            select = "com.example.springbootexam.mapper.QuestionMapper.selectById"
                    ))
            })
    List<PaperDetail> selectDetailByPid(int pid);

}
